package cn.xfdzx.android.apps.shop.util;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.ImageView;

import com.afollestad.materialdialogs.MaterialDialog;

import cn.xfdzx.android.apps.shop.R;

/**
 * @author azheng
 * @date 2018/5/24.
 * Description：圆形进度条Dialog
 */
public class ProgressDialog {

    private static volatile ProgressDialog instance;

    private ProgressDialog() {

    }

    public static ProgressDialog getInstance() {
        if (instance == null) {
            synchronized (ProgressDialog.class) {
                if (instance == null) {
                    instance = new ProgressDialog();
                }
            }
        }
        return instance;
    }

//    public MaterialDialog materialDialog;

    public Dialog materialDialog;
    public ImageView level_view;

    public void init(Context mContext) {
        materialDialog = new Dialog(mContext, R.style.NobackDialog);
    }

    public void show(Activity mContext) {
//        materialDialog = new MaterialDialog.Builder(mContext)
////                .title(R.string.progress_dialog_title)
//                .content(R.string.progress_please_wait)
//                .progress(true, 0)
//                .cancelable(true)
//                .progressIndeterminateStyle(false)
//                .show();
        materialDialog = new Dialog(mContext, R.style.NobackDialog);
        materialDialog.getWindow().setBackgroundDrawable(new ColorDrawable());
        materialDialog.setCancelable(false);
        View view = View.inflate(mContext, R.layout.loading_alert, null);

        materialDialog.setContentView(view);
        level_view = view.findViewById(R.id.level_view);

        materialDialog.setCanceledOnTouchOutside(true);
        materialDialog.show();
    }

    public void dismiss() {
//        materialDialog.dismiss();
        dismissLoadingDialog();
    }


    public void dismissLoadingDialog() {
        if (null != materialDialog && materialDialog.isShowing()) {
            materialDialog.dismiss();
        }
    }
}
